package com.deyuanyun.pic.pbf.controller.dto.defect.repair;

import com.deyuanyun.pic.pbf.controller.dto.defect.DefaultCommand;
import com.deyuanyun.pic.pbf.controller.dto.defect.ImgDto;
import com.deyuanyun.pic.pbf.enumeration.ImgCustomType;
import com.deyuanyun.pic.settings.domain.base.Attachment;
import com.deyuanyun.pic.settings.support.biz.AttachmentUtil;

import java.util.*;

/**
 *
 *
 * @author huanglw
 * @date
 *
 * History: [修改人][时间][修改描述]
 */
public class RepairDto extends DefaultCommand {

    /**
     * 备注
     */
    private String remark;

    private Map<String, List<ImgDto>> imgList;

    private String repairMethodCode;

    /**
     * 节点名称
     */
    private String nodeName;

    public String getNodeName() {
        return nodeName;
    }

    public void setNodeName(String nodeName) {
        this.nodeName = nodeName;
    }

    public String getRemark() {
        return remark;
    }

    public void setRemark(String remark) {
        this.remark = remark;
    }

    public Map<String, List<ImgDto>> getImgList() {
        return imgList;
    }

    public void setImgList(Map<String, List<ImgDto>> imgList) {
        this.imgList = imgList;
    }

    public String getRepairMethodCode() {
        return repairMethodCode;
    }

    public void setRepairMethodCode(String repairMethodCode) {
        this.repairMethodCode = repairMethodCode;
    }

    public void fromDomain(String id, String remark) {

        // 缺陷编号
        this.remark = remark;
        // 图片
        this.imgList = this.getGroupImg(id);
    }

    /**
     * 把查询出的图片分组，分成：修复前，修复中，修复后，无损检测类型，焊接作业指导书
     *
     * @param businessId
     * @return
     */
    protected  Map<String, List<ImgDto>> getGroupImg(String businessId) {
        List<Attachment> attachmentList = AttachmentUtil.getAttachmentList(businessId);
        List<ImgDto> repairBeforeImgList = new ArrayList<ImgDto>();
        List<ImgDto> repairDuringList = new ArrayList<ImgDto>();
        List<ImgDto> repairAfterImgList = new ArrayList<ImgDto>();
        List<ImgDto> ndttypeImgList = new ArrayList<ImgDto>();
        List<ImgDto> weldworktypeImgList = new ArrayList<ImgDto>();
        List<ImgDto> allImgList = new ArrayList<ImgDto>();
        for (Attachment attachment : attachmentList) {
            ImgDto imgDto = new ImgDto();
            imgDto.fromDomain(attachment);
            if (ImgCustomType.REPAIR_BEFORE.toString().equals(attachment.getCustomType())) {
                repairBeforeImgList.add(imgDto);
            } else if (ImgCustomType.REPAIR_DURING.toString().equals(attachment.getCustomType())) {
                repairDuringList.add(imgDto);
            } else if (ImgCustomType.REPAIR_AFTER.toString().equals(attachment.getCustomType())) {
                repairAfterImgList.add(imgDto);
            } else if (ImgCustomType.NDTTYPE.toString().equals(attachment.getCustomType())) {
                ndttypeImgList.add(imgDto);
            } else if (ImgCustomType.WELDWORKTYPE.toString().equals(attachment.getCustomType())) {
                weldworktypeImgList.add(imgDto);
            } else if (ImgCustomType.ALL.toString().equals(attachment.getCustomType())) {
                allImgList.add(imgDto);
            }
        }
        Map<String, List<ImgDto>> map = new HashMap();
        map.put(ImgCustomType.ALL.toString(), allImgList);
        map.put(ImgCustomType.REPAIR_BEFORE.toString(), repairBeforeImgList);
        map.put(ImgCustomType.REPAIR_DURING.toString(), repairDuringList);
        map.put(ImgCustomType.REPAIR_AFTER.toString(), repairAfterImgList);
        map.put(ImgCustomType.NDTTYPE.toString(), ndttypeImgList);
        map.put(ImgCustomType.WELDWORKTYPE.toString(), weldworktypeImgList);
        return map;
    }
}
